package top.tenebrous.yzl.im.observer;


import top.tenebrous.yzl.im.message.Message;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author yazhang6
 */
public abstract class AbstractChatRecord<T extends Message> {

    protected List<ImChatRecordHandlerProcessorObserver<T>> observers = new ArrayList<>();

    protected Map<ImChatRecordHandlerProcessorObserver<T>, ObserverInfoBean> observerMap = new ConcurrentHashMap<>();

    /**
     * 增加观察者方法
     *
     * @param observer
     */
    public void addObserver(ImChatRecordHandlerProcessorObserver<T> observer) {
        observers.add(observer);
    }

    public void addObserver(Map<ImChatRecordHandlerProcessorObserver<T>, ObserverInfoBean> map) {
        observerMap.putAll(map);
    }

    /**
     * 删除观察者方法
     *
     * @param observer
     */
    public void remove(ImChatRecordHandlerProcessorObserver<T> observer) {
        observers.remove(observer);
    }

    /**
     * 通知观察者
     */
    public abstract void notifyObserver(List<T> message);

}